package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.system.domain.RmStudentInfo;
import com.ruoyi.system.domain.SysDept;
import com.ruoyi.system.service.IRmStudentInfoService;
import com.ruoyi.system.service.ISysDeptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学生信息Controller
 * 
 * @author ruoyi
 * @date 2019-11-18
 */
@Controller
@RequestMapping("/system/info")
public class RmStudentInfoController extends BaseController
{
    private String prefix = "system/info";

    @Autowired
    private IRmStudentInfoService rmStudentInfoService;

    @Autowired
    private ISysDeptService deptService;



    @RequiresPermissions("system:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询学生信息列表
     */
    @RequiresPermissions("system:info:list")
    @PostMapping("/list")
    @ResponseBody
    public List<RmStudentInfo> list(RmStudentInfo rmStudentInfo)
    {
        startPage();
        List<RmStudentInfo> list = rmStudentInfoService.selectRmStudentInfoList(rmStudentInfo);
        //测试
        //上传文件路径
        String filePath = RuoYiConfig.getUploadPath();
        System.out.println("filePath " + filePath);
        return list;
    }

    /**
     * 导出学生信息列表
     */
    @RequiresPermissions("system:info:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RmStudentInfo rmStudentInfo)
    {
        List<RmStudentInfo> list = rmStudentInfoService.selectRmStudentInfoList(rmStudentInfo);
        ExcelUtil<RmStudentInfo> util = new ExcelUtil<RmStudentInfo>(RmStudentInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 新增学生信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学生信息
     */
    @RequiresPermissions("system:info:add")
    @Log(title = "学生信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RmStudentInfo rmStudentInfo)
    {
        return toAjax(rmStudentInfoService.insertRmStudentInfo(rmStudentInfo));
    }

    /**
     * 修改学生信息
     */
    @GetMapping("/edit/{sId}")
    public String edit(@PathVariable("sId") Long sId, ModelMap mmap)
    {
        RmStudentInfo rmStudentInfo = rmStudentInfoService.selectRmStudentInfoById(sId);
        mmap.put("rmStudentInfo", rmStudentInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存学生信息
     */
    @RequiresPermissions("system:info:edit")
    @Log(title = "学生信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RmStudentInfo rmStudentInfo)
    {
        return toAjax(rmStudentInfoService.updateRmStudentInfo(rmStudentInfo));
    }

    /**
     * 删除学生信息
     */
    @RequiresPermissions("system:info:remove")
    @Log(title = "学生信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rmStudentInfoService.deleteRmStudentInfoByIds(ids));
    }

    public static void main(String args[]) {
        //测试
        RmStudentInfoController rm = new RmStudentInfoController();
        SysDept sysDept =  rm.deptService.selectDeptbyName("运维部门");
        System.out.println("selectDeptbyName " + sysDept.getDeptId());
    }

}
